/*
 * MatWidget.h
 *
 *  Created on: 9 Nov 2012
 *      Author: hopey
 */

#ifndef MATWIDGET_H_
#define MATWIDGET_H_

#include <gtkmm/drawingarea.h>
#include <gdkmm/pixbuf.h>
#include "opencv2/imgproc/imgproc.hpp"

namespace openlid {

class MatWidget : public Gtk::DrawingArea{
public:
	MatWidget();
	MatWidget(const cv::Mat& mat);
	virtual ~MatWidget();

	void set_mat(const cv::Mat& mat);

protected:
	  //Override default signal handler:
	  //Gtk3
		//virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
		virtual bool on_expose_event(GdkEventExpose* event) override;

private:
		Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_image;

		/**
		 *  The pixbuf above is backed by the array in this matrix, so we need
		 *  to hold onto a reference to stop it from getting disposed.
		 *
		 *  An alternative would be to have a Mat* pointer, and increment its reference count
		 *  manually when we create the pixbuf, and decrement it when we're done with it. Dunno if
		 *  this'd be faster.
		 *
		 */
		cv::Mat m_mat_image;
};
} /* namespace openlid */
#endif /* MATWIDGET_H_ */
